{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# \"backtesting a grid of multi-strategy parameters\"\n",
    "> \"multi-strategy parameter optimization cannot be easier than this\"\n",
    "\n",
    "- toc: true\n",
    "- branch: master\n",
    "- badges: true\n",
    "- comments: true\n",
    "- author: Jerome de Leon\n",
    "- categories: [backtest, grid search, multi-strat]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"https://colab.research.google.com/github/enzoampil/fastquant/blob/master/examples/2020-05-10-backtest_multi_strategy.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# uncomment to install in colab\n",
    "# !pip3 install fastquant"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Define strategies in a dictionary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Starting Portfolio Value: 100000.00\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 35\n",
      "slow_period : 50\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 70\n",
      "rsi_lower : 30\n",
      "2018-07-06, BUY CREATE, 251.00\n",
      "2018-07-06, Cash: 100000.0\n",
      "2018-07-06, Price: 251.0\n",
      "2018-07-06, Buy prop size: 395\n",
      "2018-07-06, Afforded size: 395\n",
      "2018-07-06, Final size: 395\n",
      "2018-07-09, BUY EXECUTED, Price: 251.00, Cost: 99145.00, Comm 743.59\n",
      "2018-08-01, SELL CREATE, 276.00\n",
      "2018-08-02, SELL EXECUTED, Price: 276.00, Cost: 99145.00, Comm 817.65\n",
      "2018-08-02, OPERATION PROFIT, GROSS 9875.00, NET 8313.76\n",
      "2018-08-29, BUY CREATE, 287.40\n",
      "2018-08-29, Cash: 108313.76250000001\n",
      "2018-08-29, Price: 287.4\n",
      "2018-08-29, Buy prop size: 373\n",
      "2018-08-29, Afforded size: 373\n",
      "2018-08-29, Final size: 373\n",
      "2018-08-30, BUY EXECUTED, Price: 287.40, Cost: 107200.20, Comm 804.00\n",
      "2018-10-08, SELL CREATE, 252.40\n",
      "2018-10-08, BUY CREATE, 243.00\n",
      "2018-10-08, Cash: 309.5610000000147\n",
      "2018-10-08, Price: 243.0\n",
      "2018-10-08, Buy prop size: 1\n",
      "2018-10-08, Afforded size: 1\n",
      "2018-10-08, Final size: 1\n",
      "2018-10-09, SELL EXECUTED, Price: 252.40, Cost: 107200.20, Comm 706.09\n",
      "2018-10-09, OPERATION PROFIT, GROSS -13055.00, NET -14565.09\n",
      "2018-10-09, BUY EXECUTED, Price: 243.00, Cost: 243.00, Comm 1.82\n",
      "2018-11-22, BUY CREATE, 285.00\n",
      "2018-11-22, Cash: 93503.84950000003\n",
      "2018-11-22, Price: 285.0\n",
      "2018-11-22, Buy prop size: 325\n",
      "2018-11-22, Afforded size: 325\n",
      "2018-11-22, Final size: 325\n",
      "2018-11-23, BUY EXECUTED, Price: 285.00, Cost: 92625.00, Comm 694.69\n",
      "2018-12-19, SELL CREATE, 303.00\n",
      "2018-12-20, SELL EXECUTED, Price: 303.00, Cost: 92868.00, Comm 740.83\n",
      "Final PnL: -1778.67\n",
      "Final PnL: -1778.67\n",
      "==================================================\n",
      "Number of strat runs: 1\n",
      "Number of strats per run: 2\n",
      "Strat names: ['smac', 'rsi']\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 35, 'smac.slow_period': 50, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 70, 'rsi.rsi_lower': 30}\n",
      "OrderedDict([('rtot', -0.0179468149815959), ('ravg', -7.385520568557983e-05), ('rnorm', -0.018439387134145634), ('rnorm100', -1.8439387134145633)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "Time used (seconds): 0.06001472473144531\n",
      "Optimal parameters: {'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 35, 'smac.slow_period': 50, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 70, 'rsi.rsi_lower': 30}\n",
      "Optimal metrics: {'rtot': -0.0179468149815959, 'ravg': -7.385520568557983e-05, 'rnorm': -0.018439387134145634, 'rnorm100': -1.8439387134145633, 'sharperatio': None, 'pnl': -1778.67, 'final_value': 98221.32700000002}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(1, 16)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from fastquant import backtest, get_stock_data\n",
    "df = get_stock_data(\"JFC\", \"2018-01-01\", \"2019-01-01\")\n",
    "\n",
    "# Utilize single set of parameters\n",
    "strats = { \n",
    "    \"smac\": {\"fast_period\": 35, \"slow_period\": 50}, \n",
    "    \"rsi\": {\"rsi_lower\": 30, \"rsi_upper\": 70}\n",
    "} \n",
    "res = backtest(\"multi\", df, strats=strats)\n",
    "res.shape\n",
    "# (1, 16)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Utilize auto grid search"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Starting Portfolio Value: 100000.00\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 10\n",
      "slow_period : 40\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 70\n",
      "rsi_lower : 20\n",
      "2018-04-12, BUY CREATE, 300.00\n",
      "2018-04-12, Cash: 100000.0\n",
      "2018-04-12, Price: 300.0\n",
      "2018-04-12, Buy prop size: 330\n",
      "2018-04-12, Afforded size: 330\n",
      "2018-04-12, Final size: 330\n",
      "2018-04-13, BUY EXECUTED, Price: 300.00, Cost: 99000.00, Comm 742.50\n",
      "2018-04-13, SELL CREATE, 291.60\n",
      "2018-04-16, SELL EXECUTED, Price: 291.60, Cost: 99000.00, Comm 721.71\n",
      "2018-04-16, OPERATION PROFIT, GROSS -2772.00, NET -4236.21\n",
      "2018-08-03, BUY CREATE, 277.00\n",
      "2018-08-03, Cash: 95763.79\n",
      "2018-08-03, Price: 277.0\n",
      "2018-08-03, Buy prop size: 342\n",
      "2018-08-03, Afforded size: 342\n",
      "2018-08-03, Final size: 342\n",
      "2018-08-06, BUY EXECUTED, Price: 277.00, Cost: 94734.00, Comm 710.50\n",
      "2018-09-19, SELL CREATE, 271.00\n",
      "2018-09-20, SELL EXECUTED, Price: 271.00, Cost: 94734.00, Comm 695.12\n",
      "2018-09-20, OPERATION PROFIT, GROSS -2052.00, NET -3457.62\n",
      "2018-10-30, BUY CREATE, 264.00\n",
      "2018-10-30, Cash: 92306.16999999998\n",
      "2018-10-30, Price: 264.0\n",
      "2018-10-30, Buy prop size: 346\n",
      "2018-10-30, Afforded size: 346\n",
      "2018-10-30, Final size: 346\n",
      "2018-10-31, BUY EXECUTED, Price: 264.00, Cost: 91344.00, Comm 685.08\n",
      "2018-12-19, SELL CREATE, 303.00\n",
      "2018-12-20, SELL EXECUTED, Price: 303.00, Cost: 91344.00, Comm 786.28\n",
      "Final PnL: 4328.8\n",
      "Final PnL: 4328.8\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 10\n",
      "slow_period : 40\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 80\n",
      "rsi_lower : 20\n",
      "2018-04-12, BUY CREATE, 300.00\n",
      "2018-04-12, Cash: 100000.0\n",
      "2018-04-12, Price: 300.0\n",
      "2018-04-12, Buy prop size: 330\n",
      "2018-04-12, Afforded size: 330\n",
      "2018-04-12, Final size: 330\n",
      "2018-04-13, BUY EXECUTED, Price: 300.00, Cost: 99000.00, Comm 742.50\n",
      "2018-04-13, SELL CREATE, 291.60\n",
      "2018-04-16, SELL EXECUTED, Price: 291.60, Cost: 99000.00, Comm 721.71\n",
      "2018-04-16, OPERATION PROFIT, GROSS -2772.00, NET -4236.21\n",
      "2018-08-03, BUY CREATE, 277.00\n",
      "2018-08-03, Cash: 95763.79\n",
      "2018-08-03, Price: 277.0\n",
      "2018-08-03, Buy prop size: 342\n",
      "2018-08-03, Afforded size: 342\n",
      "2018-08-03, Final size: 342\n",
      "2018-08-06, BUY EXECUTED, Price: 277.00, Cost: 94734.00, Comm 710.50\n",
      "2018-09-19, SELL CREATE, 271.00\n",
      "2018-09-20, SELL EXECUTED, Price: 271.00, Cost: 94734.00, Comm 695.12\n",
      "2018-09-20, OPERATION PROFIT, GROSS -2052.00, NET -3457.62\n",
      "2018-10-30, BUY CREATE, 264.00\n",
      "2018-10-30, Cash: 92306.16999999998\n",
      "2018-10-30, Price: 264.0\n",
      "2018-10-30, Buy prop size: 346\n",
      "2018-10-30, Afforded size: 346\n",
      "2018-10-30, Final size: 346\n",
      "2018-10-31, BUY EXECUTED, Price: 264.00, Cost: 91344.00, Comm 685.08\n",
      "Final PnL: 1239.89\n",
      "Final PnL: 1239.89\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 10\n",
      "slow_period : 40\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 70\n",
      "rsi_lower : 30\n",
      "2018-04-12, BUY CREATE, 300.00\n",
      "2018-04-12, Cash: 100000.0\n",
      "2018-04-12, Price: 300.0\n",
      "2018-04-12, Buy prop size: 330\n",
      "2018-04-12, Afforded size: 330\n",
      "2018-04-12, Final size: 330\n",
      "2018-04-13, BUY EXECUTED, Price: 300.00, Cost: 99000.00, Comm 742.50\n",
      "2018-04-13, SELL CREATE, 291.60\n",
      "2018-04-16, SELL EXECUTED, Price: 291.60, Cost: 99000.00, Comm 721.71\n",
      "2018-04-16, OPERATION PROFIT, GROSS -2772.00, NET -4236.21\n",
      "2018-07-06, BUY CREATE, 251.00\n",
      "2018-07-06, Cash: 95763.79\n",
      "2018-07-06, Price: 251.0\n",
      "2018-07-06, Buy prop size: 378\n",
      "2018-07-06, Afforded size: 378\n",
      "2018-07-06, Final size: 378\n",
      "2018-07-09, BUY EXECUTED, Price: 251.00, Cost: 94878.00, Comm 711.59\n",
      "2018-08-01, SELL CREATE, 276.00\n",
      "2018-08-02, SELL EXECUTED, Price: 276.00, Cost: 94878.00, Comm 782.46\n",
      "2018-08-02, OPERATION PROFIT, GROSS 9450.00, NET 7955.95\n",
      "2018-08-03, BUY CREATE, 277.00\n",
      "2018-08-03, Cash: 103719.74499999998\n",
      "2018-08-03, Price: 277.0\n",
      "2018-08-03, Buy prop size: 371\n",
      "2018-08-03, Afforded size: 371\n",
      "2018-08-03, Final size: 371\n",
      "2018-08-06, BUY EXECUTED, Price: 277.00, Cost: 102767.00, Comm 770.75\n",
      "2018-09-19, SELL CREATE, 271.00\n",
      "2018-09-20, SELL EXECUTED, Price: 271.00, Cost: 102767.00, Comm 754.06\n",
      "2018-09-20, OPERATION PROFIT, GROSS -2226.00, NET -3750.81\n",
      "2018-10-08, BUY CREATE, 243.00\n",
      "2018-10-08, Cash: 99968.93499999998\n",
      "2018-10-08, Price: 243.0\n",
      "2018-10-08, Buy prop size: 407\n",
      "2018-10-08, Afforded size: 407\n",
      "2018-10-08, Final size: 407\n",
      "2018-10-09, BUY EXECUTED, Price: 243.00, Cost: 98901.00, Comm 741.76\n",
      "2018-10-30, BUY CREATE, 264.00\n",
      "2018-10-30, Cash: 326.1774999999832\n",
      "2018-10-30, Price: 264.0\n",
      "2018-10-30, Buy prop size: 1\n",
      "2018-10-30, Afforded size: 1\n",
      "2018-10-30, Final size: 1\n",
      "2018-10-31, BUY EXECUTED, Price: 264.00, Cost: 264.00, Comm 1.98\n",
      "2018-12-19, SELL CREATE, 303.00\n",
      "2018-12-20, SELL EXECUTED, Price: 303.00, Cost: 99165.00, Comm 927.18\n",
      "Final PnL: 22757.02\n",
      "Final PnL: 22757.02\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 10\n",
      "slow_period : 40\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 80\n",
      "rsi_lower : 30\n",
      "2018-04-12, BUY CREATE, 300.00\n",
      "2018-04-12, Cash: 100000.0\n",
      "2018-04-12, Price: 300.0\n",
      "2018-04-12, Buy prop size: 330\n",
      "2018-04-12, Afforded size: 330\n",
      "2018-04-12, Final size: 330\n",
      "2018-04-13, BUY EXECUTED, Price: 300.00, Cost: 99000.00, Comm 742.50\n",
      "2018-04-13, SELL CREATE, 291.60\n",
      "2018-04-16, SELL EXECUTED, Price: 291.60, Cost: 99000.00, Comm 721.71\n",
      "2018-04-16, OPERATION PROFIT, GROSS -2772.00, NET -4236.21\n",
      "2018-07-06, BUY CREATE, 251.00\n",
      "2018-07-06, Cash: 95763.79\n",
      "2018-07-06, Price: 251.0\n",
      "2018-07-06, Buy prop size: 378\n",
      "2018-07-06, Afforded size: 378\n",
      "2018-07-06, Final size: 378\n",
      "2018-07-09, BUY EXECUTED, Price: 251.00, Cost: 94878.00, Comm 711.59\n",
      "2018-09-19, SELL CREATE, 271.00\n",
      "2018-09-20, SELL EXECUTED, Price: 271.00, Cost: 94878.00, Comm 768.28\n",
      "2018-10-08, BUY CREATE, 243.00\n",
      "2018-10-08, Cash: 101843.91999999998\n",
      "2018-10-08, Price: 243.0\n",
      "2018-10-08, Buy prop size: 415\n",
      "2018-10-08, Afforded size: 415\n",
      "2018-10-08, Final size: 415\n",
      "2018-10-09, BUY EXECUTED, Price: 243.00, Cost: 100845.00, Comm 756.34\n",
      "Final PnL: 21339.58\n",
      "Final PnL: 21339.58\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 10\n",
      "slow_period : 60\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 70\n",
      "rsi_lower : 20\n",
      "2018-04-23, BUY CREATE, 294.00\n",
      "2018-04-23, Cash: 100000.0\n",
      "2018-04-23, Price: 294.0\n",
      "2018-04-23, Buy prop size: 337\n",
      "2018-04-23, Afforded size: 337\n",
      "2018-04-23, Final size: 337\n",
      "2018-04-24, BUY EXECUTED, Price: 294.00, Cost: 99078.00, Comm 743.08\n",
      "2018-04-26, SELL CREATE, 282.00\n",
      "2018-04-27, SELL EXECUTED, Price: 282.00, Cost: 99078.00, Comm 712.75\n",
      "2018-04-27, OPERATION PROFIT, GROSS -4044.00, NET -5499.84\n",
      "2018-08-08, BUY CREATE, 276.80\n",
      "2018-08-08, Cash: 94500.15999999999\n",
      "2018-08-08, Price: 276.8\n",
      "2018-08-08, Buy prop size: 338\n",
      "2018-08-08, Afforded size: 338\n",
      "2018-08-08, Final size: 338\n",
      "2018-08-09, BUY EXECUTED, Price: 276.80, Cost: 93558.40, Comm 701.69\n",
      "2018-09-28, SELL CREATE, 252.00\n",
      "2018-10-01, SELL EXECUTED, Price: 252.00, Cost: 93558.40, Comm 638.82\n",
      "2018-10-01, OPERATION PROFIT, GROSS -8382.40, NET -9722.91\n",
      "2018-11-06, BUY CREATE, 278.60\n",
      "2018-11-06, Cash: 84777.25199999998\n",
      "2018-11-06, Price: 278.6\n",
      "2018-11-06, Buy prop size: 301\n",
      "2018-11-06, Afforded size: 301\n",
      "2018-11-06, Final size: 301\n",
      "2018-11-07, BUY EXECUTED, Price: 278.60, Cost: 83858.60, Comm 628.94\n",
      "2018-12-19, SELL CREATE, 303.00\n",
      "2018-12-20, SELL EXECUTED, Price: 303.00, Cost: 83858.60, Comm 684.02\n",
      "Final PnL: -9191.31\n",
      "Final PnL: -9191.31\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 10\n",
      "slow_period : 60\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 80\n",
      "rsi_lower : 20\n",
      "2018-04-23, BUY CREATE, 294.00\n",
      "2018-04-23, Cash: 100000.0\n",
      "2018-04-23, Price: 294.0\n",
      "2018-04-23, Buy prop size: 337\n",
      "2018-04-23, Afforded size: 337\n",
      "2018-04-23, Final size: 337\n",
      "2018-04-24, BUY EXECUTED, Price: 294.00, Cost: 99078.00, Comm 743.08\n",
      "2018-04-26, SELL CREATE, 282.00\n",
      "2018-04-27, SELL EXECUTED, Price: 282.00, Cost: 99078.00, Comm 712.75\n",
      "2018-04-27, OPERATION PROFIT, GROSS -4044.00, NET -5499.84\n",
      "2018-08-08, BUY CREATE, 276.80\n",
      "2018-08-08, Cash: 94500.15999999999\n",
      "2018-08-08, Price: 276.8\n",
      "2018-08-08, Buy prop size: 338\n",
      "2018-08-08, Afforded size: 338\n",
      "2018-08-08, Final size: 338\n",
      "2018-08-09, BUY EXECUTED, Price: 276.80, Cost: 93558.40, Comm 701.69\n",
      "2018-09-28, SELL CREATE, 252.00\n",
      "2018-10-01, SELL EXECUTED, Price: 252.00, Cost: 93558.40, Comm 638.82\n",
      "2018-10-01, OPERATION PROFIT, GROSS -8382.40, NET -9722.91\n",
      "2018-11-06, BUY CREATE, 278.60\n",
      "2018-11-06, Cash: 84777.25199999998\n",
      "2018-11-06, Price: 278.6\n",
      "2018-11-06, Buy prop size: 301\n",
      "2018-11-06, Afforded size: 301\n",
      "2018-11-06, Final size: 301\n",
      "2018-11-07, BUY EXECUTED, Price: 278.60, Cost: 83858.60, Comm 628.94\n",
      "Final PnL: -11878.49\n",
      "Final PnL: -11878.49\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 10\n",
      "slow_period : 60\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 70\n",
      "rsi_lower : 30\n",
      "2018-04-23, BUY CREATE, 294.00\n",
      "2018-04-23, Cash: 100000.0\n",
      "2018-04-23, Price: 294.0\n",
      "2018-04-23, Buy prop size: 337\n",
      "2018-04-23, Afforded size: 337\n",
      "2018-04-23, Final size: 337\n",
      "2018-04-24, BUY EXECUTED, Price: 294.00, Cost: 99078.00, Comm 743.08\n",
      "2018-04-26, SELL CREATE, 282.00\n",
      "2018-04-27, SELL EXECUTED, Price: 282.00, Cost: 99078.00, Comm 712.75\n",
      "2018-04-27, OPERATION PROFIT, GROSS -4044.00, NET -5499.84\n",
      "2018-07-06, BUY CREATE, 251.00\n",
      "2018-07-06, Cash: 94500.15999999999\n",
      "2018-07-06, Price: 251.0\n",
      "2018-07-06, Buy prop size: 373\n",
      "2018-07-06, Afforded size: 373\n",
      "2018-07-06, Final size: 373\n",
      "2018-07-09, BUY EXECUTED, Price: 251.00, Cost: 93623.00, Comm 702.17\n",
      "2018-08-01, SELL CREATE, 276.00\n",
      "2018-08-02, SELL EXECUTED, Price: 276.00, Cost: 93623.00, Comm 772.11\n",
      "2018-08-02, OPERATION PROFIT, GROSS 9325.00, NET 7850.72\n",
      "2018-08-08, BUY CREATE, 276.80\n",
      "2018-08-08, Cash: 102350.87749999999\n",
      "2018-08-08, Price: 276.8\n",
      "2018-08-08, Buy prop size: 366\n",
      "2018-08-08, Afforded size: 366\n",
      "2018-08-08, Final size: 366\n",
      "2018-08-09, BUY EXECUTED, Price: 276.80, Cost: 101308.80, Comm 759.82\n",
      "2018-09-28, SELL CREATE, 252.00\n",
      "2018-10-01, SELL EXECUTED, Price: 252.00, Cost: 101308.80, Comm 691.74\n",
      "2018-10-01, OPERATION PROFIT, GROSS -9076.80, NET -10528.36\n",
      "2018-10-08, BUY CREATE, 243.00\n",
      "2018-10-08, Cash: 91822.52149999997\n",
      "2018-10-08, Price: 243.0\n",
      "2018-10-08, Buy prop size: 374\n",
      "2018-10-08, Afforded size: 374\n",
      "2018-10-08, Final size: 374\n",
      "2018-10-09, BUY EXECUTED, Price: 243.00, Cost: 90882.00, Comm 681.61\n",
      "2018-12-19, SELL CREATE, 303.00\n",
      "2018-12-20, SELL EXECUTED, Price: 303.00, Cost: 90882.00, Comm 849.91\n",
      "2018-12-20, OPERATION PROFIT, GROSS 22440.00, NET 20908.47\n",
      "Final PnL: 12730.99\n",
      "Final PnL: 12730.99\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 10\n",
      "slow_period : 60\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 80\n",
      "rsi_lower : 30\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2018-04-23, BUY CREATE, 294.00\n",
      "2018-04-23, Cash: 100000.0\n",
      "2018-04-23, Price: 294.0\n",
      "2018-04-23, Buy prop size: 337\n",
      "2018-04-23, Afforded size: 337\n",
      "2018-04-23, Final size: 337\n",
      "2018-04-24, BUY EXECUTED, Price: 294.00, Cost: 99078.00, Comm 743.08\n",
      "2018-04-26, SELL CREATE, 282.00\n",
      "2018-04-27, SELL EXECUTED, Price: 282.00, Cost: 99078.00, Comm 712.75\n",
      "2018-04-27, OPERATION PROFIT, GROSS -4044.00, NET -5499.84\n",
      "2018-07-06, BUY CREATE, 251.00\n",
      "2018-07-06, Cash: 94500.15999999999\n",
      "2018-07-06, Price: 251.0\n",
      "2018-07-06, Buy prop size: 373\n",
      "2018-07-06, Afforded size: 373\n",
      "2018-07-06, Final size: 373\n",
      "2018-07-09, BUY EXECUTED, Price: 251.00, Cost: 93623.00, Comm 702.17\n",
      "2018-09-28, SELL CREATE, 252.00\n",
      "2018-10-01, SELL EXECUTED, Price: 252.00, Cost: 93623.00, Comm 704.97\n",
      "2018-10-08, BUY CREATE, 243.00\n",
      "2018-10-08, Cash: 93466.01749999999\n",
      "2018-10-08, Price: 243.0\n",
      "2018-10-08, Buy prop size: 381\n",
      "2018-10-08, Afforded size: 381\n",
      "2018-10-08, Final size: 381\n",
      "2018-10-09, BUY EXECUTED, Price: 243.00, Cost: 92583.00, Comm 694.37\n",
      "Final PnL: 11364.44\n",
      "Final PnL: 11364.44\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 15\n",
      "slow_period : 40\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 70\n",
      "rsi_lower : 20\n",
      "2018-08-07, BUY CREATE, 270.00\n",
      "2018-08-07, Cash: 100000.0\n",
      "2018-08-07, Price: 270.0\n",
      "2018-08-07, Buy prop size: 367\n",
      "2018-08-07, Afforded size: 367\n",
      "2018-08-07, Final size: 367\n",
      "2018-08-08, BUY EXECUTED, Price: 270.00, Cost: 99090.00, Comm 743.17\n",
      "2018-09-21, SELL CREATE, 271.00\n",
      "2018-09-24, SELL EXECUTED, Price: 271.00, Cost: 99090.00, Comm 745.93\n",
      "2018-09-24, OPERATION PROFIT, GROSS 367.00, NET -1122.10\n",
      "2018-11-05, BUY CREATE, 280.00\n",
      "2018-11-05, Cash: 98877.89749999999\n",
      "2018-11-05, Price: 280.0\n",
      "2018-11-05, Buy prop size: 350\n",
      "2018-11-05, Afforded size: 350\n",
      "2018-11-05, Final size: 350\n",
      "2018-11-06, BUY EXECUTED, Price: 280.00, Cost: 98000.00, Comm 735.00\n",
      "2018-12-19, SELL CREATE, 303.00\n",
      "2018-12-20, SELL EXECUTED, Price: 303.00, Cost: 98000.00, Comm 795.38\n",
      "Final PnL: 5397.52\n",
      "Final PnL: 5397.52\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 15\n",
      "slow_period : 40\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 80\n",
      "rsi_lower : 20\n",
      "2018-08-07, BUY CREATE, 270.00\n",
      "2018-08-07, Cash: 100000.0\n",
      "2018-08-07, Price: 270.0\n",
      "2018-08-07, Buy prop size: 367\n",
      "2018-08-07, Afforded size: 367\n",
      "2018-08-07, Final size: 367\n",
      "2018-08-08, BUY EXECUTED, Price: 270.00, Cost: 99090.00, Comm 743.17\n",
      "2018-09-21, SELL CREATE, 271.00\n",
      "2018-09-24, SELL EXECUTED, Price: 271.00, Cost: 99090.00, Comm 745.93\n",
      "2018-09-24, OPERATION PROFIT, GROSS 367.00, NET -1122.10\n",
      "2018-11-05, BUY CREATE, 280.00\n",
      "2018-11-05, Cash: 98877.89749999999\n",
      "2018-11-05, Price: 280.0\n",
      "2018-11-05, Buy prop size: 350\n",
      "2018-11-05, Afforded size: 350\n",
      "2018-11-05, Final size: 350\n",
      "2018-11-06, BUY EXECUTED, Price: 280.00, Cost: 98000.00, Comm 735.00\n",
      "Final PnL: 2272.9\n",
      "Final PnL: 2272.9\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 15\n",
      "slow_period : 40\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 70\n",
      "rsi_lower : 30\n",
      "2018-07-06, BUY CREATE, 251.00\n",
      "2018-07-06, Cash: 100000.0\n",
      "2018-07-06, Price: 251.0\n",
      "2018-07-06, Buy prop size: 395\n",
      "2018-07-06, Afforded size: 395\n",
      "2018-07-06, Final size: 395\n",
      "2018-07-09, BUY EXECUTED, Price: 251.00, Cost: 99145.00, Comm 743.59\n",
      "2018-08-01, SELL CREATE, 276.00\n",
      "2018-08-02, SELL EXECUTED, Price: 276.00, Cost: 99145.00, Comm 817.65\n",
      "2018-08-02, OPERATION PROFIT, GROSS 9875.00, NET 8313.76\n",
      "2018-08-07, BUY CREATE, 270.00\n",
      "2018-08-07, Cash: 108313.76250000001\n",
      "2018-08-07, Price: 270.0\n",
      "2018-08-07, Buy prop size: 397\n",
      "2018-08-07, Afforded size: 397\n",
      "2018-08-07, Final size: 397\n",
      "2018-08-08, BUY EXECUTED, Price: 270.00, Cost: 107190.00, Comm 803.92\n",
      "2018-09-21, SELL CREATE, 271.00\n",
      "2018-09-24, SELL EXECUTED, Price: 271.00, Cost: 107190.00, Comm 806.90\n",
      "2018-09-24, OPERATION PROFIT, GROSS 397.00, NET -1213.83\n",
      "2018-10-08, BUY CREATE, 243.00\n",
      "2018-10-08, Cash: 107099.93500000001\n",
      "2018-10-08, Price: 243.0\n",
      "2018-10-08, Buy prop size: 437\n",
      "2018-10-08, Afforded size: 437\n",
      "2018-10-08, Final size: 437\n",
      "2018-10-09, BUY EXECUTED, Price: 243.00, Cost: 106191.00, Comm 796.43\n",
      "2018-12-19, SELL CREATE, 303.00\n",
      "2018-12-20, SELL EXECUTED, Price: 303.00, Cost: 106191.00, Comm 993.08\n",
      "2018-12-20, OPERATION PROFIT, GROSS 26220.00, NET 24430.49\n",
      "Final PnL: 31530.42\n",
      "Final PnL: 31530.42\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 15\n",
      "slow_period : 40\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 80\n",
      "rsi_lower : 30\n",
      "2018-07-06, BUY CREATE, 251.00\n",
      "2018-07-06, Cash: 100000.0\n",
      "2018-07-06, Price: 251.0\n",
      "2018-07-06, Buy prop size: 395\n",
      "2018-07-06, Afforded size: 395\n",
      "2018-07-06, Final size: 395\n",
      "2018-07-09, BUY EXECUTED, Price: 251.00, Cost: 99145.00, Comm 743.59\n",
      "2018-09-21, SELL CREATE, 271.00\n",
      "2018-09-24, SELL EXECUTED, Price: 271.00, Cost: 99145.00, Comm 802.84\n",
      "2018-10-08, BUY CREATE, 243.00\n",
      "2018-10-08, Cash: 106353.57500000001\n",
      "2018-10-08, Price: 243.0\n",
      "2018-10-08, Buy prop size: 433\n",
      "2018-10-08, Afforded size: 433\n",
      "2018-10-08, Final size: 433\n",
      "2018-10-09, BUY EXECUTED, Price: 243.00, Cost: 105219.00, Comm 789.14\n",
      "2018-11-05, BUY CREATE, 280.00\n",
      "2018-11-05, Cash: 345.4325000000116\n",
      "2018-11-05, Price: 280.0\n",
      "2018-11-05, Buy prop size: 1\n",
      "2018-11-05, Afforded size: 1\n",
      "2018-11-05, Final size: 1\n",
      "2018-11-06, BUY EXECUTED, Price: 280.00, Cost: 280.00, Comm 2.10\n",
      "Final PnL: 26704.53\n",
      "Final PnL: 26704.53\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 15\n",
      "slow_period : 60\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 70\n",
      "rsi_lower : 20\n",
      "2018-08-14, BUY CREATE, 273.40\n",
      "2018-08-14, Cash: 100000.0\n",
      "2018-08-14, Price: 273.4\n",
      "2018-08-14, Buy prop size: 362\n",
      "2018-08-14, Afforded size: 362\n",
      "2018-08-14, Final size: 362\n",
      "2018-08-15, BUY EXECUTED, Price: 273.40, Cost: 98970.80, Comm 742.28\n",
      "2018-10-01, SELL CREATE, 250.00\n",
      "2018-10-02, SELL EXECUTED, Price: 250.00, Cost: 98970.80, Comm 678.75\n",
      "2018-10-02, OPERATION PROFIT, GROSS -8470.80, NET -9891.83\n",
      "2018-11-08, BUY CREATE, 280.00\n",
      "2018-11-08, Cash: 90108.16900000001\n",
      "2018-11-08, Price: 280.0\n",
      "2018-11-08, Buy prop size: 319\n",
      "2018-11-08, Afforded size: 319\n",
      "2018-11-08, Final size: 319\n",
      "2018-11-09, BUY EXECUTED, Price: 280.00, Cost: 89320.00, Comm 669.90\n",
      "2018-12-19, SELL CREATE, 303.00\n",
      "2018-12-20, SELL EXECUTED, Price: 303.00, Cost: 89320.00, Comm 724.93\n",
      "Final PnL: -3949.66\n",
      "Final PnL: -3949.66\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 15\n",
      "slow_period : 60\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 80\n",
      "rsi_lower : 20\n",
      "2018-08-14, BUY CREATE, 273.40\n",
      "2018-08-14, Cash: 100000.0\n",
      "2018-08-14, Price: 273.4\n",
      "2018-08-14, Buy prop size: 362\n",
      "2018-08-14, Afforded size: 362\n",
      "2018-08-14, Final size: 362\n",
      "2018-08-15, BUY EXECUTED, Price: 273.40, Cost: 98970.80, Comm 742.28\n",
      "2018-10-01, SELL CREATE, 250.00\n",
      "2018-10-02, SELL EXECUTED, Price: 250.00, Cost: 98970.80, Comm 678.75\n",
      "2018-10-02, OPERATION PROFIT, GROSS -8470.80, NET -9891.83\n",
      "2018-11-08, BUY CREATE, 280.00\n",
      "2018-11-08, Cash: 90108.16900000001\n",
      "2018-11-08, Price: 280.0\n",
      "2018-11-08, Buy prop size: 319\n",
      "2018-11-08, Afforded size: 319\n",
      "2018-11-08, Final size: 319\n",
      "2018-11-09, BUY EXECUTED, Price: 280.00, Cost: 89320.00, Comm 669.90\n",
      "Final PnL: -6797.53\n",
      "Final PnL: -6797.53\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 15\n",
      "slow_period : 60\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 70\n",
      "rsi_lower : 30\n",
      "2018-07-06, BUY CREATE, 251.00\n",
      "2018-07-06, Cash: 100000.0\n",
      "2018-07-06, Price: 251.0\n",
      "2018-07-06, Buy prop size: 395\n",
      "2018-07-06, Afforded size: 395\n",
      "2018-07-06, Final size: 395\n",
      "2018-07-09, BUY EXECUTED, Price: 251.00, Cost: 99145.00, Comm 743.59\n",
      "2018-08-01, SELL CREATE, 276.00\n",
      "2018-08-02, SELL EXECUTED, Price: 276.00, Cost: 99145.00, Comm 817.65\n",
      "2018-08-02, OPERATION PROFIT, GROSS 9875.00, NET 8313.76\n",
      "2018-08-14, BUY CREATE, 273.40\n",
      "2018-08-14, Cash: 108313.76250000001\n",
      "2018-08-14, Price: 273.4\n",
      "2018-08-14, Buy prop size: 392\n",
      "2018-08-14, Afforded size: 392\n",
      "2018-08-14, Final size: 392\n",
      "2018-08-15, BUY EXECUTED, Price: 273.40, Cost: 107172.80, Comm 803.80\n",
      "2018-10-01, SELL CREATE, 250.00\n",
      "2018-10-02, SELL EXECUTED, Price: 250.00, Cost: 107172.80, Comm 735.00\n",
      "2018-10-02, OPERATION PROFIT, GROSS -9172.80, NET -10711.60\n",
      "2018-10-08, BUY CREATE, 243.00\n",
      "2018-10-08, Cash: 97602.16650000002\n",
      "2018-10-08, Price: 243.0\n",
      "2018-10-08, Buy prop size: 398\n",
      "2018-10-08, Afforded size: 398\n",
      "2018-10-08, Final size: 398\n",
      "2018-10-09, BUY EXECUTED, Price: 243.00, Cost: 96714.00, Comm 725.36\n",
      "2018-12-19, SELL CREATE, 303.00\n",
      "2018-12-20, SELL EXECUTED, Price: 303.00, Cost: 96714.00, Comm 904.45\n",
      "2018-12-20, OPERATION PROFIT, GROSS 23880.00, NET 22250.19\n",
      "Final PnL: 19852.36\n",
      "Final PnL: 19852.36\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "fast_period : 15\n",
      "slow_period : 60\n",
      "===Global level arguments===\n",
      "init_cash : 100000\n",
      "buy_prop : 1\n",
      "sell_prop : 1\n",
      "===Strategy level arguments===\n",
      "rsi_period : 14\n",
      "rsi_upper : 80\n",
      "rsi_lower : 30\n",
      "2018-07-06, BUY CREATE, 251.00\n",
      "2018-07-06, Cash: 100000.0\n",
      "2018-07-06, Price: 251.0\n",
      "2018-07-06, Buy prop size: 395\n",
      "2018-07-06, Afforded size: 395\n",
      "2018-07-06, Final size: 395\n",
      "2018-07-09, BUY EXECUTED, Price: 251.00, Cost: 99145.00, Comm 743.59\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2018-10-01, SELL CREATE, 250.00\n",
      "2018-10-02, SELL EXECUTED, Price: 250.00, Cost: 99145.00, Comm 740.62\n",
      "2018-10-08, BUY CREATE, 243.00\n",
      "2018-10-08, Cash: 98120.7875\n",
      "2018-10-08, Price: 243.0\n",
      "2018-10-08, Buy prop size: 400\n",
      "2018-10-08, Afforded size: 400\n",
      "2018-10-08, Final size: 400\n",
      "2018-10-09, BUY EXECUTED, Price: 243.00, Cost: 97200.00, Comm 729.00\n",
      "Final PnL: 16911.79\n",
      "Final PnL: 16911.79\n",
      "==================================================\n",
      "Number of strat runs: 16\n",
      "Number of strats per run: 2\n",
      "Strat names: ['smac', 'rsi']\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 10, 'smac.slow_period': 40, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 70, 'rsi.rsi_lower': 20}\n",
      "OrderedDict([('rtot', 0.042377312386123134), ('ravg', 0.000174392232041659), ('rnorm', 0.04492680768865365), ('rnorm100', 4.492680768865364)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 10, 'smac.slow_period': 40, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 80, 'rsi.rsi_lower': 20}\n",
      "OrderedDict([('rtot', 0.012322663161177035), ('ravg', 5.071054798838286e-05), ('rnorm', 0.012861059182548444), ('rnorm100', 1.2861059182548444)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 10, 'smac.slow_period': 40, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 70, 'rsi.rsi_lower': 30}\n",
      "OrderedDict([('rtot', 0.2050367480952209), ('ravg', 0.0008437726259062589), ('rnorm', 0.23692777159818812), ('rnorm100', 23.69277715981881)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 10, 'smac.slow_period': 40, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 80, 'rsi.rsi_lower': 30}\n",
      "OrderedDict([('rtot', 0.19342289577512692), ('ravg', 0.00079597899495937), ('rnorm', 0.2221195736378016), ('rnorm100', 22.21195736378016)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 10, 'smac.slow_period': 60, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 70, 'rsi.rsi_lower': 20}\n",
      "OrderedDict([('rtot', -0.0964152001144457), ('ravg', -0.0003967703708413403), ('rnorm', -0.0951500349055751), ('rnorm100', -9.51500349055751)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 10, 'smac.slow_period': 60, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 80, 'rsi.rsi_lower': 20}\n",
      "OrderedDict([('rtot', -0.12645350010683382), ('ravg', -0.0005203847741021968), ('rnorm', -0.12290236382425088), ('rnorm100', -12.290236382425087)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 10, 'smac.slow_period': 60, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 70, 'rsi.rsi_lower': 30}\n",
      "OrderedDict([('rtot', 0.11983418838139474), ('ravg', 0.0004931448081538878), ('rnorm', 0.13232437790797075), ('rnorm100', 13.232437790797075)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 10, 'smac.slow_period': 60, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 80, 'rsi.rsi_lower': 30}\n",
      "OrderedDict([('rtot', 0.10763792539049269), ('ravg', 0.00044295442547527856), ('rnorm', 0.11809295492841805), ('rnorm100', 11.809295492841805)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 15, 'smac.slow_period': 40, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 70, 'rsi.rsi_lower': 20}\n",
      "OrderedDict([('rtot', 0.052568944150307696), ('ravg', 0.00021633310349920864), ('rnorm', 0.05602931158519976), ('rnorm100', 5.602931158519977)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 15, 'smac.slow_period': 40, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 80, 'rsi.rsi_lower': 20}\n",
      "OrderedDict([('rtot', 0.022474520295117782), ('ravg', 9.248773783999087e-05), ('rnorm', 0.02358063841261683), ('rnorm100', 2.358063841261683)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 15, 'smac.slow_period': 40, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 70, 'rsi.rsi_lower': 30}\n",
      "OrderedDict([('rtot', 0.2740679696753637), ('ravg', 0.0011278517270591098), ('rnorm', 0.3287234047301618), ('rnorm100', 32.87234047301618)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 15, 'smac.slow_period': 40, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 80, 'rsi.rsi_lower': 30}\n",
      "OrderedDict([('rtot', 0.23668767417980946), ('ravg', 0.0009740233505341953), ('rnorm', 0.2782013371264516), ('rnorm100', 27.820133712645163)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 15, 'smac.slow_period': 60, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 70, 'rsi.rsi_lower': 20}\n",
      "OrderedDict([('rtot', -0.04029774133997106), ('ravg', -0.00016583432650193853), ('rnorm', -0.04092907566388783), ('rnorm100', -4.092907566388783)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 15, 'smac.slow_period': 60, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 80, 'rsi.rsi_lower': 20}\n",
      "OrderedDict([('rtot', -0.07039597323112812), ('ravg', -0.00028969536309106223), ('rnorm', -0.07040217397345756), ('rnorm100', -7.0402173973457565)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 15, 'smac.slow_period': 60, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 70, 'rsi.rsi_lower': 30}\n",
      "OrderedDict([('rtot', 0.18109043677660316), ('ravg', 0.0007452281348831406), ('rnorm', 0.20658914422764327), ('rnorm100', 20.658914422764326)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "**************************************************\n",
      "--------------------------------------------------\n",
      "{'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 15, 'smac.slow_period': 60, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 80, 'rsi.rsi_lower': 30}\n",
      "OrderedDict([('rtot', 0.15624951145271396), ('ravg', 0.0006430021047436788), ('rnorm', 0.1759031967451431), ('rnorm100', 17.59031967451431)])\n",
      "OrderedDict([('sharperatio', None)])\n",
      "Time used (seconds): 0.9437069892883301\n",
      "Optimal parameters: {'init_cash': 100000, 'buy_prop': 1, 'sell_prop': 1, 'execution_type': 'close', 'smac.fast_period': 15, 'smac.slow_period': 40, 'rsi.rsi_period': 14, 'rsi.rsi_upper': 70, 'rsi.rsi_lower': 30}\n",
      "Optimal metrics: {'rtot': 0.2740679696753637, 'ravg': 0.0011278517270591098, 'rnorm': 0.3287234047301618, 'rnorm100': 32.87234047301618, 'sharperatio': None, 'pnl': 31530.42, 'final_value': 131530.42}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(16, 16)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "strats_opt = { \n",
    "    \"smac\": {\"fast_period\": [10,15], \"slow_period\": [40, 60]}, \n",
    "    \"rsi\": {\"rsi_lower\": [20, 30], \"rsi_upper\": [70, 80]} \n",
    "}\n",
    "\n",
    "res_opt = backtest(\"multi\", df, strats=strats_opt)\n",
    "res_opt.shape\n",
    "# (4, 16)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>init_cash</th>\n",
       "      <th>buy_prop</th>\n",
       "      <th>sell_prop</th>\n",
       "      <th>execution_type</th>\n",
       "      <th>smac.fast_period</th>\n",
       "      <th>smac.slow_period</th>\n",
       "      <th>rsi.rsi_period</th>\n",
       "      <th>rsi.rsi_upper</th>\n",
       "      <th>rsi.rsi_lower</th>\n",
       "      <th>rtot</th>\n",
       "      <th>ravg</th>\n",
       "      <th>rnorm</th>\n",
       "      <th>rnorm100</th>\n",
       "      <th>sharperatio</th>\n",
       "      <th>pnl</th>\n",
       "      <th>final_value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>15</td>\n",
       "      <td>40</td>\n",
       "      <td>14</td>\n",
       "      <td>70</td>\n",
       "      <td>30</td>\n",
       "      <td>0.274068</td>\n",
       "      <td>0.001128</td>\n",
       "      <td>0.328723</td>\n",
       "      <td>32.872340</td>\n",
       "      <td>None</td>\n",
       "      <td>31530.42</td>\n",
       "      <td>131530.4200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>15</td>\n",
       "      <td>40</td>\n",
       "      <td>14</td>\n",
       "      <td>80</td>\n",
       "      <td>30</td>\n",
       "      <td>0.236688</td>\n",
       "      <td>0.000974</td>\n",
       "      <td>0.278201</td>\n",
       "      <td>27.820134</td>\n",
       "      <td>None</td>\n",
       "      <td>26704.53</td>\n",
       "      <td>126704.5325</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>10</td>\n",
       "      <td>40</td>\n",
       "      <td>14</td>\n",
       "      <td>70</td>\n",
       "      <td>30</td>\n",
       "      <td>0.205037</td>\n",
       "      <td>0.000844</td>\n",
       "      <td>0.236928</td>\n",
       "      <td>23.692777</td>\n",
       "      <td>None</td>\n",
       "      <td>22757.02</td>\n",
       "      <td>122757.0175</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>10</td>\n",
       "      <td>40</td>\n",
       "      <td>14</td>\n",
       "      <td>80</td>\n",
       "      <td>30</td>\n",
       "      <td>0.193423</td>\n",
       "      <td>0.000796</td>\n",
       "      <td>0.222120</td>\n",
       "      <td>22.211957</td>\n",
       "      <td>None</td>\n",
       "      <td>21339.58</td>\n",
       "      <td>121339.5825</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>15</td>\n",
       "      <td>60</td>\n",
       "      <td>14</td>\n",
       "      <td>70</td>\n",
       "      <td>30</td>\n",
       "      <td>0.181090</td>\n",
       "      <td>0.000745</td>\n",
       "      <td>0.206589</td>\n",
       "      <td>20.658914</td>\n",
       "      <td>None</td>\n",
       "      <td>19852.36</td>\n",
       "      <td>119852.3565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>15</td>\n",
       "      <td>60</td>\n",
       "      <td>14</td>\n",
       "      <td>80</td>\n",
       "      <td>30</td>\n",
       "      <td>0.156250</td>\n",
       "      <td>0.000643</td>\n",
       "      <td>0.175903</td>\n",
       "      <td>17.590320</td>\n",
       "      <td>None</td>\n",
       "      <td>16911.79</td>\n",
       "      <td>116911.7875</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>10</td>\n",
       "      <td>60</td>\n",
       "      <td>14</td>\n",
       "      <td>70</td>\n",
       "      <td>30</td>\n",
       "      <td>0.119834</td>\n",
       "      <td>0.000493</td>\n",
       "      <td>0.132324</td>\n",
       "      <td>13.232438</td>\n",
       "      <td>None</td>\n",
       "      <td>12730.99</td>\n",
       "      <td>112730.9915</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>10</td>\n",
       "      <td>60</td>\n",
       "      <td>14</td>\n",
       "      <td>80</td>\n",
       "      <td>30</td>\n",
       "      <td>0.107638</td>\n",
       "      <td>0.000443</td>\n",
       "      <td>0.118093</td>\n",
       "      <td>11.809295</td>\n",
       "      <td>None</td>\n",
       "      <td>11364.44</td>\n",
       "      <td>111364.4450</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>15</td>\n",
       "      <td>40</td>\n",
       "      <td>14</td>\n",
       "      <td>70</td>\n",
       "      <td>20</td>\n",
       "      <td>0.052569</td>\n",
       "      <td>0.000216</td>\n",
       "      <td>0.056029</td>\n",
       "      <td>5.602931</td>\n",
       "      <td>None</td>\n",
       "      <td>5397.52</td>\n",
       "      <td>105397.5225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>10</td>\n",
       "      <td>40</td>\n",
       "      <td>14</td>\n",
       "      <td>70</td>\n",
       "      <td>20</td>\n",
       "      <td>0.042377</td>\n",
       "      <td>0.000174</td>\n",
       "      <td>0.044927</td>\n",
       "      <td>4.492681</td>\n",
       "      <td>None</td>\n",
       "      <td>4328.80</td>\n",
       "      <td>104328.8050</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>15</td>\n",
       "      <td>40</td>\n",
       "      <td>14</td>\n",
       "      <td>80</td>\n",
       "      <td>20</td>\n",
       "      <td>0.022475</td>\n",
       "      <td>0.000092</td>\n",
       "      <td>0.023581</td>\n",
       "      <td>2.358064</td>\n",
       "      <td>None</td>\n",
       "      <td>2272.90</td>\n",
       "      <td>102272.8975</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>10</td>\n",
       "      <td>40</td>\n",
       "      <td>14</td>\n",
       "      <td>80</td>\n",
       "      <td>20</td>\n",
       "      <td>0.012323</td>\n",
       "      <td>0.000051</td>\n",
       "      <td>0.012861</td>\n",
       "      <td>1.286106</td>\n",
       "      <td>None</td>\n",
       "      <td>1239.89</td>\n",
       "      <td>101239.8900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>15</td>\n",
       "      <td>60</td>\n",
       "      <td>14</td>\n",
       "      <td>70</td>\n",
       "      <td>20</td>\n",
       "      <td>-0.040298</td>\n",
       "      <td>-0.000166</td>\n",
       "      <td>-0.040929</td>\n",
       "      <td>-4.092908</td>\n",
       "      <td>None</td>\n",
       "      <td>-3949.66</td>\n",
       "      <td>96050.3415</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>15</td>\n",
       "      <td>60</td>\n",
       "      <td>14</td>\n",
       "      <td>80</td>\n",
       "      <td>20</td>\n",
       "      <td>-0.070396</td>\n",
       "      <td>-0.000290</td>\n",
       "      <td>-0.070402</td>\n",
       "      <td>-7.040217</td>\n",
       "      <td>None</td>\n",
       "      <td>-6797.53</td>\n",
       "      <td>93202.4690</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>10</td>\n",
       "      <td>60</td>\n",
       "      <td>14</td>\n",
       "      <td>70</td>\n",
       "      <td>20</td>\n",
       "      <td>-0.096415</td>\n",
       "      <td>-0.000397</td>\n",
       "      <td>-0.095150</td>\n",
       "      <td>-9.515003</td>\n",
       "      <td>None</td>\n",
       "      <td>-9191.31</td>\n",
       "      <td>90808.6900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>100000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>close</td>\n",
       "      <td>10</td>\n",
       "      <td>60</td>\n",
       "      <td>14</td>\n",
       "      <td>80</td>\n",
       "      <td>20</td>\n",
       "      <td>-0.126454</td>\n",
       "      <td>-0.000520</td>\n",
       "      <td>-0.122902</td>\n",
       "      <td>-12.290236</td>\n",
       "      <td>None</td>\n",
       "      <td>-11878.49</td>\n",
       "      <td>88121.5125</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    init_cash  buy_prop  sell_prop execution_type  smac.fast_period  \\\n",
       "0      100000         1          1          close                15   \n",
       "1      100000         1          1          close                15   \n",
       "2      100000         1          1          close                10   \n",
       "3      100000         1          1          close                10   \n",
       "4      100000         1          1          close                15   \n",
       "5      100000         1          1          close                15   \n",
       "6      100000         1          1          close                10   \n",
       "7      100000         1          1          close                10   \n",
       "8      100000         1          1          close                15   \n",
       "9      100000         1          1          close                10   \n",
       "10     100000         1          1          close                15   \n",
       "11     100000         1          1          close                10   \n",
       "12     100000         1          1          close                15   \n",
       "13     100000         1          1          close                15   \n",
       "14     100000         1          1          close                10   \n",
       "15     100000         1          1          close                10   \n",
       "\n",
       "    smac.slow_period  rsi.rsi_period  rsi.rsi_upper  rsi.rsi_lower      rtot  \\\n",
       "0                 40              14             70             30  0.274068   \n",
       "1                 40              14             80             30  0.236688   \n",
       "2                 40              14             70             30  0.205037   \n",
       "3                 40              14             80             30  0.193423   \n",
       "4                 60              14             70             30  0.181090   \n",
       "5                 60              14             80             30  0.156250   \n",
       "6                 60              14             70             30  0.119834   \n",
       "7                 60              14             80             30  0.107638   \n",
       "8                 40              14             70             20  0.052569   \n",
       "9                 40              14             70             20  0.042377   \n",
       "10                40              14             80             20  0.022475   \n",
       "11                40              14             80             20  0.012323   \n",
       "12                60              14             70             20 -0.040298   \n",
       "13                60              14             80             20 -0.070396   \n",
       "14                60              14             70             20 -0.096415   \n",
       "15                60              14             80             20 -0.126454   \n",
       "\n",
       "        ravg     rnorm   rnorm100 sharperatio       pnl  final_value  \n",
       "0   0.001128  0.328723  32.872340        None  31530.42  131530.4200  \n",
       "1   0.000974  0.278201  27.820134        None  26704.53  126704.5325  \n",
       "2   0.000844  0.236928  23.692777        None  22757.02  122757.0175  \n",
       "3   0.000796  0.222120  22.211957        None  21339.58  121339.5825  \n",
       "4   0.000745  0.206589  20.658914        None  19852.36  119852.3565  \n",
       "5   0.000643  0.175903  17.590320        None  16911.79  116911.7875  \n",
       "6   0.000493  0.132324  13.232438        None  12730.99  112730.9915  \n",
       "7   0.000443  0.118093  11.809295        None  11364.44  111364.4450  \n",
       "8   0.000216  0.056029   5.602931        None   5397.52  105397.5225  \n",
       "9   0.000174  0.044927   4.492681        None   4328.80  104328.8050  \n",
       "10  0.000092  0.023581   2.358064        None   2272.90  102272.8975  \n",
       "11  0.000051  0.012861   1.286106        None   1239.89  101239.8900  \n",
       "12 -0.000166 -0.040929  -4.092908        None  -3949.66   96050.3415  \n",
       "13 -0.000290 -0.070402  -7.040217        None  -6797.53   93202.4690  \n",
       "14 -0.000397 -0.095150  -9.515003        None  -9191.31   90808.6900  \n",
       "15 -0.000520 -0.122902 -12.290236        None -11878.49   88121.5125  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_opt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
